package main

import (
	"fmt"
	"runtime"
	"time"
)

func main() {
	defer fmt.Println("go routines before work: ", runtime.NumGoroutine())
	fmt.Println("go routines before work: ", runtime.NumGoroutine())
	ch := make(chan string)
	go func() {
		ch <- "xxlocing"
	}()
	go work(ch)
	timer := time.NewTimer(5 * time.Second)
	for {
		select {
		case <-timer.C:
			fmt.Println("exiting")
			return
		default:
			time.Sleep(time.Second)
			fmt.Println("number of go routines ", runtime.NumGoroutine())
		}
	}
}

func work(strings <-chan string) {
	fmt.Println("in ", strings)

	for s := range strings {
		fmt.Println(s)
	}
	fmt.Println("work is done")
}
